package day03;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class A07_LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        //获取用户名和密码
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        //将用户名和密码存到会话域中
        HttpSession session = req.getSession();
        session.setAttribute("username",username);
        session.setAttribute("password",password);
        //在浏览器发送一个请求,发到另外一个Servlet上去(IndexServlet)
        resp.sendRedirect("/request/IndexServlet");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            doGet(req, resp);
    }
}
